package org.zxl.springbootdemo.hsqldb.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zxl.springbootdemo.hsqldb.dao.DemoDao;
import org.zxl.springbootdemo.hsqldb.dao.DemoDao2;
import org.zxl.springbootdemo.hsqldb.entity.Demo;


@RestController
public class DemoController {

    @Autowired
    private DemoDao demoDao;

    @RequestMapping("save")
    public String save(){
        Demo demoInfo = new Demo();
        demoInfo.setName("张三");
        demoInfo.setAge(20);
        demoDao.save(demoInfo);

        demoInfo = new Demo();
        demoInfo.setName("李四");
        demoInfo.setAge(30);
        demoDao.save(demoInfo);

        return "ok";
    }

    @RequestMapping("find")
    public List<Demo> find(){
        return (List<Demo>) demoDao.findAll();
    }

    @RequestMapping("findByName")
    public Demo findByName(){
        return demoDao.findByName("张三");
    }

    @Autowired
    private DemoDao2 demoDao2;

    @RequestMapping("demoCount")
    public String demoCount(){
        return demoDao2.demoCount()+"";
    }
}